package com.etxxy.member.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.etxxy.common.exception.DataException;
import com.etxxy.common.exception.ServiceException;
import com.etxxy.member.domain.Role;
import com.etxxy.member.mapper.RoleMapper;
import com.etxxy.member.service.RoleService;

@Service("roleService")
public class RoleServiceImpl implements RoleService {
	private static final Logger logger  = LoggerFactory.getLogger(RoleServiceImpl.class);
	@Autowired
	private RoleMapper roleMapper;
	
	@Override
	public Role findRoleById(String id) throws ServiceException, DataException {
		logger.info("查找角色的id={}",id);
		Role role = roleMapper.selectByPrimaryKey(id);
		return role;
	}

	@Override
	public int insertRole(Role role) throws ServiceException, DataException {
		logger.info("插入角色的role={}",JSON.toJSONString(role));
		int result = roleMapper.insert(role);
		return result;
	}

	@Override
	public int updateRole(Role role) throws ServiceException, DataException {
		logger.info("更新角色的role={}",JSON.toJSONString(role));
		int result = roleMapper.updateByPrimaryKeySelective(role);
		return result;
	}

	@Override
	public int deleteRole(String id) throws ServiceException, DataException {
		logger.info("删除角色的id={}",id);
		int result = roleMapper.deleteByPrimaryKey(id);
		return result;
	}

}
